﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyVoteMVC.Domain;
using System.Data;

namespace MyVoteMVC.Data.Repositories
{
    public class ProjectAdminRepository : AdminRepository<VT_Projects>
    {
        public override bool Add(VT_Projects entity)
        {
            if (entity.ProjectImage == null)
            {
                var image = new VT_ProjectImage() { Project_ID = entity.Project_ID };
                ctx.Entry<VT_ProjectImage>(image).State = EntityState.Added;
            }

            return base.Add(entity);
        }

        public override bool Delete(VT_Projects entity)
        {
            if (entity.ProjectImage == null)
            {
                var image = new VT_ProjectImage() { Project_ID = entity.Project_ID };

                if (ctx.Entry<VT_ProjectImage>(image).State == EntityState.Detached)
                {
                    ctx.ProjectImages.Attach(image);
                }
            }
            return base.Delete(entity);


        }
    }
}
